package org.luxor.eshop.payment.controller;

import lombok.extern.slf4j.Slf4j;
import org.luxor.commons.core.web.controller.BaseRestController;
import org.luxor.commons.core.web.data.R;
import org.luxor.eshop.payment.entity.dto.TransferDto;
import org.luxor.eshop.payment.service.PaymentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 在线支付服务
 *
 * @author Mr.Yan  @date 2019/9/19
 */
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController extends BaseRestController {

    @Resource
    private PaymentService paymentService;

    /**
     * 转账交易
     */
    @PreAuthorize("isAnonymous()")
    @PostMapping("/transfer")
    public R transfer(@RequestBody TransferDto transfer) {
        paymentService.transfer(transfer);
        return R.ok();
    }

    /**
     * 订单支付
     */
    @PreAuthorize("isAnonymous()")
    @PostMapping("/order/{orderId}")
    public R orderPayment(@PathVariable("orderId") Long orderId) {
        paymentService.orderPayment(orderId);
        return R.ok();
    }


}
